import {esri} from "../../../api/esriAPI";
import {threeManage} from "./threeManage";

export class BaseThree {
  constructor(view, ...parames) {
    this.view = view;
    threeManage.bind(view, (three) => {
      this.renderer = three.renderer;
      this.scene = three.scene;
      this.camera = three.camera;
      this.arcgisContext = three.arcgisContext;
      this.setup(...parames);
    });
  }

  setup(...parames) {
    throw new Error("请重写setup方法");
  }

  initRender() {
    // .render ( scene : Scene, camera : Camera, renderTarget : WebGLRenderTarget, forceClear : Boolean ) : null
    //     用相机(camera)渲染一个场景(scene)
    //     渲染一般是在canvas上完成的，或者是renderTarget(如果有指定)
    //     如果forceClear值是true，那么颜色、深度及模板缓存将会在渲染之前清除，即使渲染器的autoClear属性值是false
    //     即便forceClear设为true, 也可以通过将autoClearColor、autoClearStencil或autoClearDepth属性的值设为false来阻止对应缓存被清除。
    this.renderer.render(this.scene, this.camera);
  }
  //单坐标转换输出
  toRenderCoordinates(position) {
    let renderPos = [0, 0, 0];
    //将位置从给定空间参考转换为内部渲染坐标系。
    esri.externalRenderers.toRenderCoordinates(this.view, position, 0, esri.SpatialReference.WGS84, renderPos, 0, 1);
    return renderPos;
  }
//单坐标转换输出
  fromRenderCoordinates(position) {
    let renderPos = [0, 0, 0];
    esri.externalRenderers.fromRenderCoordinates(this.view,position, 0, renderPos,0, esri.SpatialReference.WGS84, 1);
    return renderPos;
  }

}
